/* eslint-disable eqeqeq */
import actionInfo from '../action'
import { productlightAdd, productlightQuery } from '../service/productlightService'

function productlightInfoReducer(state = { productlightList: [] }, action) {
    switch (action.type) {
        case actionInfo.productlight.ADD:
            return { productlightList: [...state.productlightList, action.payload] }
        case actionInfo.productlight.QUERY:
            return { productlightList: action.payload }
        default:
            return state
    }
}
export const asyncProductlightQuery = (params) => async (dispatch) => {
    let { data } = await productlightQuery(params);//做异步请求
    dispatch(productlightInfoQuery(data.msg));//
}
const productlightInfoQuery = (payload) => {
    return {
        type: actionInfo.productlight.QUERY,
        payload
    }
}
export const asyncProductlightAdd = (params) => async (dispatch) => {
    let { data } = await productlightAdd(params);//做异步请求
    if (data.code == 1) {
        dispatch(productlightInfoAdd(...data.msg));
    }
}
const productlightInfoAdd = (payload) => {
    return {
        type: actionInfo.productlight.ADD,
        payload
    }
}
export default productlightInfoReducer